class Solution {
public:
    int reverse(int x) 
    {
        if(x == 0) return 0;

        long long llx = x;
        long long tmp = abs(llx);
        string str = to_string(tmp);
        std::reverse(str.begin(),str.end());

        while(!str.empty())
        {
            if(str.back() == '0') str.pop_back();
            else break;
        }
        cout << str << endl;
        int ret = 0;
        try 
        {
            ret = stoi(str);
        }
        catch (...)
        {
            return 0;
        }
        if(x < 0) ret = -ret;
        return ret;  
    }
};